﻿using MediatR;
using Traceability.APP.Application.Command.Photo;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrerture.Interfaces;

namespace Traceability.APP.Application.CommandHandle.Photo
{
    /// <summary>
    /// 图片上传的显示
    /// </summary>
    public class ShowPhotoCommandHandle:IRequestHandler<ShowPhotoCommand,APIResult<List<Photo_Model>>>
    {
        private readonly IBaseRepository<Photo_Model> PhotoDal;

        public ShowPhotoCommandHandle(IBaseRepository<Photo_Model> photoDal)
        {
            PhotoDal = photoDal;
        }

        public Task<APIResult<List<Photo_Model>>> Handle(ShowPhotoCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Photo_Model>> result = new APIResult<List<Photo_Model>>();
            var list = PhotoDal.GetAll().Where(x => x.Batch == request.Batch && x.IsDeleted == false);
            result.Code = StateCode.Ok;
            result.Message = StateCode.Ok.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }



    }
}
